package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "purchase_", schema = "crm")
public class Purchase {
    private int purchaseId;
    private String purchaseTheme;// 采购主题
    private String purchaseNo;// 采购单号
    private Date purchaseDate;// 采购日期
    private Date purchasePredictDate;// 预计到货日期
    private Integer purchaseStatus;// 采购状态
    private Integer purchaseSort;// 采购分类
    private BigDecimal purchaseAmount;// 采购金额
    private String purchaseNote;// 采购备注
    private String purchaseContactName;// 采购客户联系人
    private BigDecimal purchaseBill;// 付款票据
    private BigDecimal purchasePaid;// 已付金额
    private Integer purchaseAppStatus;
    private Integer purchaseReturn;
    private List<Approval> approvalsByPurchaseId;
    private List<ApprovalRecord> approvalRecordsByPurchaseId;
    private List<PaymentInvoice> paymentInvoicesByPurchaseId;
    private List<PaymentPlan> paymentPlansByPurchaseId;
    private List<PaymentRecords> paymentRecordsByPurchaseId;
    private List<ProductDetail> productDetailsByPurchaseId;
    private Customer customerByCustomerId;// 供应商
    private Employee employeeByEmpId;
    private Customer customerByConCustomerId;// 对应合同客户
    private Contract contractByContractId;// 对应合同
    private Employee employeeByAppEmpId;// 审批人
    private Warehouse warehouseByWarehouseId;//仓库
    private Collection<Storage> storagesByPurchaseId;

    @Id
    @Column(name = "purchase_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "seq")
    public int getPurchaseId() {
        return purchaseId;
    }

    public void setPurchaseId(int purchaseId) {
        this.purchaseId = purchaseId;
    }


    @Basic
    @Column(name = "purchase_theme", nullable = true, length = 255)
    public String getPurchaseTheme() {
        return purchaseTheme;
    }

    public void setPurchaseTheme(String purchaseTheme) {
        this.purchaseTheme = purchaseTheme;
    }

    @Basic
    @Column(name = "purchase_no", nullable = true, length = 255)
    public String getPurchaseNo() {
        return purchaseNo;
    }

    public void setPurchaseNo(String purchaseNo) {
        this.purchaseNo = purchaseNo;
    }

    @Basic
    @Column(name = "purchase_date", nullable = true)
    public Date getPurchaseDate() {
        return purchaseDate;
    }

    public void setPurchaseDate(Date purchaseDate) {
        this.purchaseDate = purchaseDate;
    }

    @Basic
    @Column(name = "purchase_predict_date", nullable = true)
    public Date getPurchasePredictDate() {
        return purchasePredictDate;
    }

    public void setPurchasePredictDate(Date purchasePredictDate) {
        this.purchasePredictDate = purchasePredictDate;
    }

    @Basic
    @Column(name = "purchase_status", nullable = true)
    public Integer getPurchaseStatus() {
        return purchaseStatus;
    }

    public void setPurchaseStatus(Integer purchaseStatus) {
        this.purchaseStatus = purchaseStatus;
    }

    @Basic
    @Column(name = "purchase_sort", nullable = true)
    public Integer getPurchaseSort() {
        return purchaseSort;
    }

    public void setPurchaseSort(Integer purchaseSort) {
        this.purchaseSort = purchaseSort;
    }

    @Basic
    @Column(name = "purchase_amount", nullable = true, precision = 2)
    public BigDecimal getPurchaseAmount() {
        return purchaseAmount;
    }

    public void setPurchaseAmount(BigDecimal purchaseAmount) {
        this.purchaseAmount = purchaseAmount;
    }

    @Basic
    @Column(name = "purchase_note", nullable = true, length = 255)
    public String getPurchaseNote() {
        return purchaseNote;
    }

    public void setPurchaseNote(String purchaseNote) {
        this.purchaseNote = purchaseNote;
    }

    @Basic
    @Column(name = "purchase_contact_name", nullable = true, length = 255)
    public String getPurchaseContactName() {
        return purchaseContactName;
    }

    public void setPurchaseContactName(String purchaseContactName) {
        this.purchaseContactName = purchaseContactName;
    }

    @Basic
    @Column(name = "purchase_bill", nullable = true, precision = 2)
    public BigDecimal getPurchaseBill() {
        return purchaseBill;
    }

    public void setPurchaseBill(BigDecimal purchaseBill) {
        this.purchaseBill = purchaseBill;
    }

    @Basic
    @Column(name = "purchase_paid", nullable = true, precision = 2)
    public BigDecimal getPurchasePaid() {
        return purchasePaid;
    }

    public void setPurchasePaid(BigDecimal purchasePaid) {
        this.purchasePaid = purchasePaid;
    }

    @Basic
    @Column(name = "purchase_app_status", nullable = true, precision = 2)
    public Integer getPurchaseAppStatus() {
        return purchaseAppStatus;
    }

    public void setPurchaseAppStatus(Integer purchaseAppStatus) {
        this.purchaseAppStatus = purchaseAppStatus;
    }

    @Basic
    @Column(name = "purchase_return", nullable = true, precision = 2)
    public Integer getPurchaseReturn() {
        return purchaseReturn;
    }

    public void setPurchaseReturn(Integer purchaseReturn) {
        this.purchaseReturn = purchaseReturn;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Purchase purchase = (Purchase) o;
        return purchaseId == purchase.purchaseId &&
                Objects.equals(purchaseTheme, purchase.purchaseTheme) &&
                Objects.equals(purchaseNo, purchase.purchaseNo) &&
                Objects.equals(purchaseDate, purchase.purchaseDate) &&
                Objects.equals(purchasePredictDate, purchase.purchasePredictDate) &&
                Objects.equals(purchaseStatus, purchase.purchaseStatus) &&
                Objects.equals(purchaseSort, purchase.purchaseSort) &&
                Objects.equals(purchaseAmount, purchase.purchaseAmount) &&
                Objects.equals(purchaseNote, purchase.purchaseNote) &&
                Objects.equals(purchaseContactName, purchase.purchaseContactName) &&
                Objects.equals(purchaseBill, purchase.purchaseBill) &&
                Objects.equals(purchasePaid, purchase.purchasePaid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(purchaseId, purchaseTheme, purchaseNo, purchaseDate, purchasePredictDate, purchaseStatus, purchaseSort, purchaseAmount, purchaseNote, purchaseContactName, purchaseBill, purchasePaid);
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<Approval> getApprovalsByPurchaseId() {
        return approvalsByPurchaseId;
    }

    public void setApprovalsByPurchaseId(List<Approval> approvalsByPurchaseId) {
        this.approvalsByPurchaseId = approvalsByPurchaseId;
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<ApprovalRecord> getApprovalRecordsByPurchaseId() {
        return approvalRecordsByPurchaseId;
    }

    public void setApprovalRecordsByPurchaseId(List<ApprovalRecord> approvalRecordsByPurchaseId) {
        this.approvalRecordsByPurchaseId = approvalRecordsByPurchaseId;
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<PaymentInvoice> getPaymentInvoicesByPurchaseId() {
        return paymentInvoicesByPurchaseId;
    }

    public void setPaymentInvoicesByPurchaseId(List<PaymentInvoice> paymentInvoicesByPurchaseId) {
        this.paymentInvoicesByPurchaseId = paymentInvoicesByPurchaseId;
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<PaymentPlan> getPaymentPlansByPurchaseId() {
        return paymentPlansByPurchaseId;
    }

    public void setPaymentPlansByPurchaseId(List<PaymentPlan> paymentPlansByPurchaseId) {
        this.paymentPlansByPurchaseId = paymentPlansByPurchaseId;
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<PaymentRecords> getPaymentRecordsByPurchaseId() {
        return paymentRecordsByPurchaseId;
    }

    public void setPaymentRecordsByPurchaseId(List<PaymentRecords> paymentRecordsByPurchaseId) {
        this.paymentRecordsByPurchaseId = paymentRecordsByPurchaseId;
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<ProductDetail> getProductDetailsByPurchaseId() {
        return productDetailsByPurchaseId;
    }

    public void setProductDetailsByPurchaseId(List<ProductDetail> productDetailsByPurchaseId) {
        this.productDetailsByPurchaseId = productDetailsByPurchaseId;
    }

    @ManyToOne
    @JoinColumn(name = "customer_id", referencedColumnName = "customer_id")
    public Customer getCustomerByCustomerId() {
        return customerByCustomerId;
    }

    public void setCustomerByCustomerId(Customer customerByCustomerId) {
        this.customerByCustomerId = customerByCustomerId;
    }

    @ManyToOne
    @JoinColumn(name = "emp_id", referencedColumnName = "emp_id")
    public Employee getEmployeeByEmpId() {
        return employeeByEmpId;
    }

    public void setEmployeeByEmpId(Employee employeeByEmpId) {
        this.employeeByEmpId = employeeByEmpId;
    }

    @ManyToOne
    @JoinColumn(name = "con_customer_id", referencedColumnName = "customer_id")
    public Customer getCustomerByConCustomerId() {
        return customerByConCustomerId;
    }

    public void setCustomerByConCustomerId(Customer customerByConCustomerId) {
        this.customerByConCustomerId = customerByConCustomerId;
    }

    @ManyToOne
    @JoinColumn(name = "app_emp_id", referencedColumnName = "emp_id")
    public Employee getEmployeeByAppEmpId() {
        return employeeByAppEmpId;
    }

    public void setEmployeeByAppEmpId(Employee employeeByAppEmpId) {
        this.employeeByAppEmpId = employeeByAppEmpId;
    }

    @ManyToOne
    @JoinColumn(name = "contract_id", referencedColumnName = "contract_id")
    public Contract getContractByContractId() {
        return contractByContractId;
    }

    public void setContractByContractId(Contract contractByContractId) {
        this.contractByContractId = contractByContractId;
    }


    @ManyToOne
    @JoinColumn(name = "warehouse_id", referencedColumnName = "warehouse_id")
    public Warehouse getWarehouseByWarehouseId() {
        return warehouseByWarehouseId;
    }

    public void setWarehouseByWarehouseId(Warehouse warehouseByWarehouseId) {
        this.warehouseByWarehouseId = warehouseByWarehouseId;
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId")
    public Collection<Storage> getStoragesByPurchaseId() {
        return storagesByPurchaseId;
    }

    public void setStoragesByPurchaseId(Collection<Storage> storagesByPurchaseId) {
        this.storagesByPurchaseId = storagesByPurchaseId;
    }
}
